//
//  DMRegistDController.m
//  DMGME
//
//  Created by ihope99 on 15/9/10.
//  Copyright (c) 2015年 GYP. All rights reserved.
//

#import "DMRegistDController.h"
#import "ExamineBController.h"
#import "DMHomeViewController.h"
#import "AFNetworking.h"

@interface DMRegistDController ()
{
    NSString *_string2;
}
@end

@implementation DMRegistDController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"注册3"];
    _passWordTextF.inputAccessoryView = [self GetInputAccessoryView];
    _passWordTextF.secureTextEntry = YES;
    _passWordTooTextF.secureTextEntry = YES;
    _passWordTooTextF.inputAccessoryView = [self GetInputAccessoryView];
    self.view.backgroundColor = [UIColor whiteColor];
    [self AddLeftImageBtn:[UIImage imageNamed:@"fanhui_03 2"]target:self action:@selector(GoBack)];
    if ([_titleType isEqualToString:@"1"]) {
        [_titleLable setText:_titleStr];
            _string2 = [_titleStr substringWithRange:NSMakeRange(12, 11)];
//        NSLog(@"_string2 == %@",_string2);
    }else if([_titleType isEqualToString:@"3"]){
        
        [_titleLable setText:@"您是省级代理请直接输入密码完成注册"];
    }
    else{
        [_titleLable setText:@"2"];
    }
    //注册完成
    [_registFinished addTarget:self action:@selector(_registFinishedClick:) forControlEvents:UIControlEventTouchUpInside];
    // Do any additional setup after loading the view from its nib.
}
- (void)_registFinishedClick:(UIButton *)btn{
    
    if (!_passWordTextF||_passWordTextF.text.length == 0) {
        [self showMsg:@"请输入密码"];
    }else if (!_passWordTooTextF||_passWordTooTextF.text.length == 0){
        [self showMsg:@"请再次输入密码"];
    }else{
    
    if ([_titleType isEqualToString:@"3"]) {
        
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [dict setValue: [AFDownManager MD5String:@"%^&*dongmangoug!@#$setPassword"] forKey:@"token"];
        [dict setValue: @"setPassword" forKey:@"action"];
        [dict setValue: _passWordTextF.text forKey:@"password"];
        [dict setValue: _passWordTooTextF.text forKey:@"repassword"];
         [dict setValue: _shopID forKey:@"id"];

//        NSLog(@"dict === %@",dict);
        
        [AFDownManager POST:REGISTERNET parameters:dict success:^(id responseObject) {
            
//            NSLog(@"responseObject == %@",responseObject);
//            NSLog(@"desc == %@",responseObject[@"desc"]);
            if ([responseObject[@"code"] intValue] == 0) {
                
                DMHomeViewController *dmHomeVC = [[DMHomeViewController alloc] init];
                UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:dmHomeVC];
                [self presentViewController:nav animated:YES completion:nil];
                self.view.window.rootViewController = nav;
                kkUserDict = nil;
                kkStatus = @"1" ;
                kkUserDict = responseObject[@"data"];

            }
            
        } failure:^(NSError *error) {
//            NSLog(@"uydfhgjkvcdes==%@",error);
        }];

    }
     else{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict = _mDict;
    
    [dict setValue: [AFDownManager MD5String:@"%^&*dongmangoug!@#$complete"] forKey:@"token"];
    [dict setValue: @"complete" forKey:@"action"];
    [dict setValue: _passWordTextF.text forKey:@"password"];
    [dict setValue: _passWordTooTextF.text forKey:@"repassword"];
        
//    NSLog(@"%@",dict);
    
    [AFDownManager POST:REGISTERNET parameters:dict success:^(id responseObject) {
//        NSLog(@"%@",responseObject);
//        NSLog(@"%@",responseObject[@"desc"]);
        if ([responseObject[@"code"] intValue] == 0) {
            
            kkUserDict = nil;
            kkUserDict = responseObject[@"data"];
//            NSLog(@"%@",kkUserDict);
        
        ExamineBController *exaVC = [[ExamineBController alloc] init];
            exaVC.mMobile = responseObject[@"data"][@"mobile"];
            exaVC.mRealname = responseObject[@"data"][@"realname"];
            exaVC.mAgentPhone = _string2;
//            NSLog(@"==%@",exaVC.mAgentPhone);
        [self.navigationController pushViewController:exaVC animated:YES];
        }else{
            [self showMsg:responseObject[@"desc"]];
        }
        
    } failure:^(NSError *error) {
    }];
   }
  }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
